<!--
* @description:车辆管理
* @fileName: VehicleManagement
* @author:李周蓬
* @date:2021-1-
* @后台人员:李周蓬
-->
<template>
  <div>
    <div>
      <el-row>
        <el-col :span="3">厂牌型号：</el-col>
        <el-col :span="5"
          ><el-input v-model="carBrand" placeholder="请输入内容"></el-input
        ></el-col>
        <el-col :span="3">车牌号：</el-col>
        <el-col :span="5"
          ><el-input v-model="license" placeholder="请输入内容"></el-input
        ></el-col>
        <el-col :span="3">司机姓名：</el-col>
        <el-col :span="5"
          ><el-input v-model="driverName" placeholder="请输入内容"></el-input
        ></el-col>
      </el-row>
      <el-row>
        <el-col :span="3">所属公司：</el-col>
        <el-col :span="5">
          <el-select v-model="companyId" placeholder="请选择">
            <el-option
              v-for="item in bindData"
              :key="item.value"
              :label="item.CompanyName"
              :value="item.Id"
            >
            </el-option>
          </el-select>
        </el-col>
        
      </el-row>
      
    </div>
     <div>
      <el-row>
        <el-col :span="6" class="kk">
          <el-button type="primary" @click="show">查询</el-button>
          <el-button type="primary">重置</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-button type="primary" @click="tianjia">新增</el-button>
          <el-button type="primary" @click="dels">删除</el-button>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-table
        ref="multipleTable"
        :data="showData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="CarBrand" label="厂牌型号"> </el-table-column>
        <el-table-column prop="License" label="车牌号"> </el-table-column>
        <el-table-column prop="DriverName" label="司机名称"> </el-table-column>
        <el-table-column prop="CompanyName" label="所属公司"> </el-table-column>
        <el-table-column prop="CarType" label="车型"> </el-table-column>
        <el-table-column prop="CarColor" label="车辆颜色"> </el-table-column>
        <el-table-column prop="PurchaseTimes" label="购置日期">
        </el-table-column>
        <el-table-column prop="MarketingNumber" label="营运证号">
        </el-table-column>
        <el-table-column prop="ExpiryTimes" label="保险到期时间">
        </el-table-column>
        <el-table-column prop="CheckTimes" label="车检到期时间">
        </el-table-column>
        <el-table-column prop="Kilometre" label="保养公里数"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <a href="#" @click="update(scope.row)">编辑</a>
            <a href="#" @click="del(scope.row.Id)">删除</a>
            <a href="#" @click="check(scope.row)">查看</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageindex"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalcount"
      >
      </el-pagination>
    </div>
    <!-- 查看车辆信息 -->
    <el-dialog
      title="查看车辆信息"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>厂牌型号：</td>
          <td>
            <el-input
              v-model="checkData.CarBrand"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>车牌号:</td>
          <td>
            <el-input
              v-model="checkData.License"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>司机姓名：</td>
          <td>
            <el-input
              v-model="checkData.DriverName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>所属公司:</td>
          <td>
            <el-input
              v-model="checkData.CompanyName"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>车型：</td>
          <td>
            <el-input
              v-model="checkData.CarType"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>车辆颜色:</td>
          <td>
            <el-input
              v-model="checkData.CarColor"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>购置日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.PurchaseTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>营运证号:</td>
          <td>
            <el-input
              v-model="checkData.MarketingNumber"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>保险到期日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.ExpiryTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>年检到期日期:</td>
          <td>
            <el-date-picker
              v-model="checkData.CheckTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td>保养公里数设置：</td>
          <td>
            <el-input
              v-model="checkData.Kilometre"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <!-- <tr>
          <td>车辆照片：</td>
          <td>
            <el-input
              v-model="checkData.CarImg"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>保险卡照片：</td>
          <td>
            <el-input
              v-model="checkData.ExpiryImg"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr> -->
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 编辑车辆信息 -->
    <el-dialog
      title="编辑车辆信息"
      :visible.sync="dialogVisibles"
      width="60%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>厂牌型号：</td>
          <td>
            <el-input
              v-model="checkData.CarBrand"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>车牌号:</td>
          <td>
            <el-input
              v-model="checkData.License"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>司机姓名：</td>
          <td>
            <el-input
              v-model="checkData.DriverName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>所属公司:</td>
          <td>
            <el-select v-model="checkData.CompanyId" placeholder="请选择">
              <el-option
                v-for="item in bindData"
                :key="item.value"
                :label="item.CompanyName"
                :value="item.Id"
              >
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>车型：</td>
          <td>
            <el-input
              v-model="checkData.CarType"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>车辆颜色:</td>
          <td>
            <el-input
              v-model="checkData.CarColor"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>购置日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.PurchaseTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>营运证号:</td>
          <td>
            <el-input
              v-model="checkData.MarketingNumber"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>保险到期日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.ExpiryTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>年检到期日期:</td>
          <td>
            <el-date-picker
              v-model="checkData.CheckTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td>保养公里数设置：</td>
          <td>
            <el-input
              v-model="checkData.Kilometre"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <!-- <tr>
          <td>车辆照片：</td>
          <td>
            <el-input
              v-model="checkData.CarImg"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>保险卡照片：</td>
          <td>
            <el-input
              v-model="checkData.ExpiryImg"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr> -->
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="xiu">修 改</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showData: [],
      bindData: [],
      pageindex: 1,
      pagesize: 3,
      companyId: 0,
      carBrand: "",
      license: "",
      driverName: "",
      totalcount: 0,
      ids: [],
      dialogVisible: false,
      dialogVisibles: false,
      checkData: {
        Id: 0,
        CarNumber: "",
        CarBrand: "",
        License: "",
        DriverName: "",
        CompanyId: 0,
        CompanyName: "",
        CarType: "",
        CarColor: "",
        PurchaseTime: "",
        MarketingNumber: "",
        ExpiryTime: "",
        CheckTime: "",
        Kilometre: 0,
        CarImg: "",
        ExpiryImg: "",
        IsDelete: 0,
      },
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = [];
      for (var i = 0; i < val.length; i++) {
        this.ids.push(val[i].Id);
      }
    },
    //显示
    show() {
      this.$axios
        .get("https://localhost:44399/api/app/car/show-car/" + this.companyId, {
          params: {
            carBrand: this.carBrand,
            license: this.license,
            driverName: this.driverName,
            pageindex: this.pageindex,
            pagesize: this.pagesize,
          },
        })
        .then((res) => {
          this.showData = res.data.PageData;
          this.totalcount = res.data.PageTotal;
        });
    },
    //绑定下拉框
    bind() {
      this.$axios
        .get("https://localhost:44399/api/app/car/show-company")
        .then((res) => {
          this.bindData = res.data;
          this.bindData.unshift({ Id: 0, CompanyName: "请选择" });
        });
    },
    handleSizeChange(val) {
      this.pagesize = val;
      this.show();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pageindex = val;
      this.show();
      console.log(`当前页: ${val}`);
    },
    handleClose(done) {
      this.$confirm("确认关闭？").then(() => {
        done();
      });
    },
    //删除
    del(Id) {
      if (confirm("确定删除吗？")) {
        this.$axios
          .delete("https://localhost:44399/api/app/car/" + Id + "/del-car")
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    //批量删除
    dels() {
      if (confirm("确定删除吗？")) {
        this.$axios
          .delete(
            "https://localhost:44399/api/app/car/dels-car?ids=" + this.ids
          )
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    tianjia() {
      this.$router.push("/TheNewVehicle");
    },
    update(row) {
      this.checkData = null;
      this.dialogVisibles = true;
      this.checkData = row;
    },
    check(row) {
      this.checkData = null;
      this.dialogVisible = true;
      this.checkData = row;
    },
    xiu() {
      this.$axios
        .put("https://localhost:44399/api/app/car/update-car", this.checkData)
        .then((res) => {
          if (res.data > 0) {
            this.$message({
              type: "success",
              message: "修改成功!",
            });
            this.dialogVisibles = false;
            this.show();
          } else {
            this.$message({
              type: "error",
              message: "修改失败!",
            });
          }
        });
    },
  },
  created() {
    this.show();
    this.bind();
  },
};
</script>

<style scoped>
.kk{
  margin-top: 20px;
float: right;
}
</style>